const { MYSQL_CONF } = require('../config/setting')
const mysql = require('mysql');
const pool = mysql.createPool(MYSQL_CONF);

module.exports = function (sql, values) {
  return new Promise((resolve, reject) => {
    pool.getConnection((err, connection) => {
      if (err) {
        reject(err)
      }
      connection.query(sql, values, function (error, rows, fields) {
        if (error) {
          reject(error)
        };
        resolve(rows)
        connection.release()
      })
    })

  })
}